package com.giveme5.common.view.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.mvc.View;

import com.alibaba.fastjson.JSON;

public class ApiView implements View {

	public void render(HttpServletRequest req, HttpServletResponse resp, Object obj) throws Throwable {
		if (obj == null) {
			// 无返回值时不返回信息
		} else {
			resp.setHeader("Access-Control-Allow-Origin", "*");
			resp.setHeader("Cache-Control", "no-cache");
			if (resp.getContentType() == null)
				resp.setContentType("text/plain");
			// by mawm 改为直接采用resp.getWriter()的方式直接输出!
			String json = JSON.toJSONString(obj);
			resp.getWriter().write(json);
			resp.getWriter().flush();
			resp.flushBuffer();
		}
	}

}
